package com.cr.crandroid.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.cr.crandroid.R;
import com.cr.crandroid.bean.Car;
import com.cr.crandroid.vo.CarVo;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;
import java.util.Locale;

public class ImageTitleNumAdapter extends BannerAdapter<CarVo, ImageTitleNumAdapter.BannerViewHolder> {
    public ImageTitleNumAdapter(List<CarVo> datas) {
        super(datas);
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.banner_image_title_num, parent, false);
        return new BannerViewHolder(view);
    }

    @Override
    public void onBindView(BannerViewHolder holder, CarVo data, int position, int size) {
        Glide.with(holder.imageView).load(data.getImage().split(",")[0])
                .into(holder.imageView);
        holder.title.setText(data.getBrand());
        holder.numIndicator.setText(String.format(Locale.CHINA, "%d/%d", position + 1, size));
    }

    public static class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView title;
        TextView numIndicator;

        public BannerViewHolder(@NonNull View view) {
            super(view);
            imageView = view.findViewById(R.id.image);
            title = view.findViewById(R.id.bannerTitle);
            numIndicator = view.findViewById(R.id.numIndicator);
        }
    }
}
